import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: () => import( '../components/Login-page') },
  {
    path: '/home',
    component: () => import( '../components/HomePage.vue'),
    redirect: '/welcome',
    children: [
      { path: '/welcome',  component: () => import( '@/components/WelcomePage') },
      { path: '/users', component: () => import( '@/views/system/UsersPage') },
      { path: '/datascope', component: () => import( '@/views/system/datascopePage') },
      { path: '/role', component: () => import( '@/views/system/rolePage')  },
      { path: '/car', component: () => import( '@/views/manager/car') },
      { path: '/addCar', component: () => import( '@/views/manager/addCar') },
      { path: '/brandy', component: () => import( '@/views/manager/brandy') },
    ]
  }

]
//准备动态路由
// export const DynamicRoutes = [
//   {
//     path:'',
//     component: Layout,
//     name:'',
//     redirect:'',
//     meta:{
//       requiresAuth:true,
//       name:'首页'
//     },
//     children:[
//       {
//         path:'home',
//         component: Home,
//         name:'home',
//         meta:{
//           icon:'icon-come',
//           name:'首页'
//         },
//       }
//     ]
//   }
// ]



const router = new VueRouter({
  mode:'history',
  base:process.env.BASE_URL,
  routes
})
// 挂载导航路由守卫
router.beforeEach((to, form, next) => {
  // to将要访问的路径
  // from 代表从哪个路径跳转而来
  // next() 放行    next('/login')强行跳转
  if (to.path === '/login') return next()
  // 获取token
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})

export default router
